import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'

// Element Plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 全局样式
import './styles/index.scss'

// 工具函数
import * as utils from './utils'
import http from './utils/http'

const app = createApp(App)

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 全局属性
app.config.globalProperties.$http = http
app.config.globalProperties.$utils = utils

// 全局错误处理
app.config.errorHandler = (err, _vm, info) => {
  console.error('Vue Global Error:', err, info)
  // 可以在这里添加错误上报逻辑
}

// 全局警告处理
app.config.warnHandler = (msg, _vm, trace) => {
  console.warn('Vue Warning:', msg, trace)
}

app.use(createPinia())
app.use(router)
app.use(ElementPlus)

app.mount('#app')
